//
//  CustomTabBarController.m
//  dielianw
//
//  Created by 刘威 on 16/9/6.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "CustomTabBarController.h"
#import "CustomNavController.h"
#import "SYHomeViewController.h"

@implementation CustomTabBarController

+ (void)initialize {
    //设置底部样式
    UITabBarItem * appeatance = [UITabBarItem appearance];
    NSMutableDictionary * attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont tabBarTitleFont];
    attrs[NSForegroundColorAttributeName]= [UIColor contentColor];
    NSMutableDictionary * selectedAttrs = [NSMutableDictionary dictionary];
    selectedAttrs[NSForegroundColorAttributeName]= [UIColor orangeNavControllerTintColor];
    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];
    [appeatance setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [appeatance setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    [UITabBar appearance].translucent = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CustomNavController *homeNavController = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:[SYHomeViewController new] title:@"购药" image:[UIImage imageNamed:@"tabbar_home_icon"] selectedImage:[UIImage imageNamed:@"tabbar_home_select_icon"]]];
    
    CustomNavController *shoppingNavController = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:[UIViewController new] title:@"购物车" image:[UIImage imageNamed:@"tabbar_shopping_icon"] selectedImage:[UIImage imageNamed:@"tabbar_shopping_select_icon"]]];
    
    CustomNavController *myNavController = [[CustomNavController alloc] initWithRootViewController:[self setRootViewController:[UIViewController new] title:@"我的" image:[UIImage imageNamed:@"tabbar_my_icon"] selectedImage:[UIImage imageNamed:@"tabbar_my_select_icon"]]];
    
    
    self.viewControllers = @[homeNavController,shoppingNavController,myNavController];
}

- (UIViewController *)setRootViewController:(UIViewController *)viewController
                        title:(NSString *)title
                        image:(UIImage *)image
                  selectedImage:(UIImage *)selectedImage {
    viewController.navigationItem.title= title;
    viewController.tabBarItem.title = title;
    viewController.tabBarItem.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.tabBarItem.selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    viewController.view.backgroundColor = [UIColor whiteColor];
    return viewController;
}

@end
